package com.base.cn.platform.os.controller.op.coupon;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.entity.op.coupon.OpCouponCode;
import com.base.cn.platform.os.service.op.coupon.OpCouponBiz;
import com.base.cn.platform.os.service.op.coupon.OpCouponCodeBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 优惠券编码Controller
 *
 * @author ll
 * @create 2018-05-09
 */
@RestController
@RequestMapping("/manage/op")
public class OpCouponCodeController extends BaseController {

    @Autowired
    private OpCouponCodeBiz opCouponCodeBiz;
    @Autowired
    private OpCouponBiz opCouponBiz;

    /**
     * 修改优惠券编码状态
     * @param codeId 优惠券编码ID
     * @param status 状态
     */
    @RequestMapping("/updateCouponCodeStatus")
    public void updateCouponCodeStatus(@RequestParam("codeId") BigDecimal codeId,@RequestParam("status") int status){
        opCouponCodeBiz.updateCouponCodeStatus(codeId,status);
    }



    /**
     * 通过编码获取优惠券对象
     * @param code 优惠编码
     * @param couponData 是否设置优惠券数据对象
     * @return OpCouponCode
     */
    @RequestMapping("/findCouponCodeByCode")
    public OpCouponCode findCouponCodeByCode(@RequestParam("code") String code,
                                             @RequestParam("couponData") boolean couponData){
        return opCouponCodeBiz.findCouponCodeByCode(code,couponData);
    }

    /**
     * 通过编码获取优惠券对象
     * @param id 优惠券编码ID
     * @param couponData 是否设置优惠券数据对象
     * @return OpCouponCode
     */
    @RequestMapping("/findCouponCodeById")
    public OpCouponCode findCouponCodeById(@RequestParam("id") BigDecimal id,
                                             @RequestParam("couponData") boolean couponData){
        return opCouponCodeBiz.findCouponCodeById(id,couponData);
    }

    /**
     * 翻页搜索优惠券编码
     * @param opCouponCode
     * @param currentPage
     * @param userName
     * @param couponData
     * @return
     */
    @RequestMapping("/queryOpCouponCodeListPage")
    public PageInfo<OpCouponCode> queryOpCouponCodeListPage(@RequestBody OpCouponCode opCouponCode,
                                                            @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage,
                                                            @RequestParam(value = "userName",required = false,defaultValue = "false")boolean userName,
                                                            @RequestParam(value = "couponData",required = false,defaultValue = "false")boolean couponData){
        Pagination page = new Pagination();
        page.setCurrentPage(currentPage);
        return opCouponCodeBiz.queryUserCouponCodeListPage(page,opCouponCode,userName,couponData);
    }
    /**
     * 搜索优惠券编码
     * @param userId
     * @param status
     * @param userName
     * @param couponData
     * @return
     */
    @RequestMapping("/queryUserCouponCodeListByUserId")
    public List<OpCouponCode> queryUserCouponCodeListByUserId(@RequestParam("userId")BigDecimal userId,
                                                              @RequestParam(value = "status",required = false,defaultValue = "0")Integer status,
                                                              @RequestParam(value = "userName",required = false,defaultValue = "false")boolean userName,
                                                              @RequestParam(value = "couponData",required = false,defaultValue = "false")boolean couponData) {
        return opCouponCodeBiz.queryUserCouponCodeListByUserId(userId,status,userName,couponData);
    }

    /**
     * 批量查询
     * @param opCouponCode
     * @param userName
     * @param couponData
     * @return
     */
    @RequestMapping("/queryUserCouponCodeList")
    public List<OpCouponCode> queryUserCouponCodeList(@RequestBody OpCouponCode opCouponCode,
                                                      @RequestParam(value = "userName",required = false,defaultValue = "false")boolean userName,
                                                      @RequestParam(value = "couponData",required = false,defaultValue = "false")boolean couponData){
        return opCouponCodeBiz.queryUserCouponCodeList(opCouponCode,userName,couponData);
    }

    /**
     * 个人中心专用搜索列表
     *
     * @param currentPage   翻页
     * @param order  分组
     * @param status 优惠券状态
     * @param type 优惠券类型
     * @param userId 用户id
     */
    @RequestMapping("/queryUserCouponCode")
    public PageInfo<OpCouponCode> queryUserCouponCode(@RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage,
                                                      @RequestParam(value = "order",required = false,defaultValue = "0")Integer order,
                                                      @RequestParam(value = "status",required = false,defaultValue = "0")Integer status,
                                                      @RequestParam(value = "type",required = false,defaultValue = "0")Integer type,
                                                      @RequestParam("userId")BigDecimal userId,
                                                      @RequestParam(value = "userName",required = false,defaultValue = "false")boolean userName,
                                                      @RequestParam(value = "couponData",required = false,defaultValue = "false")boolean couponData){
        Pagination page = new Pagination();
        page.setPageSize(6);
        page.setCurrentPage(currentPage);
        return opCouponCodeBiz.queryUserCouponCode(page,order,status,type,userId,userName,couponData);
    }

    /**
     * 查询订单可用的优惠券（只用于存课程商品的订单）
     * @param paramsList 查询条件
     * @param userId 用户ID
     * @return List<OpCouponCode>
     */
    @RequestMapping("/findOrderAvailableCodeList")
    public List<OpCouponCode> findOrderAvailableCodeList(@RequestBody List<Map<String,String>> paramsList,@RequestParam("userId") BigDecimal userId){
        return opCouponCodeBiz.findOrderAvailableCodeList(paramsList,userId);
    }

    /**
     * 赠送用户优惠券
     * @param userId 用户ID
     * @param conditions 获取条件，1手动发放，2新用户注册后自动获取，3学员生日获取，4邀请注册获取，5消费任意金额获取，6免费直播发放，7活动
     * @param count 获取数量(如果数量为0量，则获取该类型的所有的优惠券的各一张编码)
     */
    @RequestMapping("/giveUserCouponCode")
    public void giveUserCouponCode(@RequestParam("userId") BigDecimal userId,
                                   @RequestParam("conditions") int conditions,
                                   @RequestParam("count") int count){
        opCouponCodeBiz.giveUserCouponCode(userId,conditions,count);
    }

    /**
     * 新用户注册后赠送优惠券
     * @param userId 用户ID
     */
    @RequestMapping("/giveUserRegCouponCode")
    public void giveUserRegCouponCode(@RequestParam("userId") BigDecimal userId){
        opCouponCodeBiz.giveUserRegCouponCode(userId);
    }

    /**
     * 用户注册赠送优惠券
     * @param userId 用户ID
     */
    @RequestMapping("/giveUserBirthdayCode")
    public void giveUserBirthdayCode(@RequestParam("userId") BigDecimal userId){
        opCouponCodeBiz.giveUserBirthdayCode(userId);
    }

    /**
     * 用户消费任意金额赠送优惠券
     * @param userId 用户ID
     */
    @RequestMapping("/giveUserConsumePrice")
    public void giveUserConsumePrice(@RequestParam("userId") BigDecimal userId){
        opCouponCodeBiz.giveUserConsumePrice(userId);
    }

    /**
     * 赠送用户参加免费直播直播赠送优惠券
     * @param userId 用户ID
     * @param openCourseId　免费直播ID
     */
    @RequestMapping("/giveUserCourseOpenCode")
    public void giveUserCourseOpenCode(@RequestParam("userId") BigDecimal userId,@RequestParam("openCourseId") BigDecimal openCourseId){
        opCouponCodeBiz.giveUserCourseOpenCode(userId,openCourseId);
    }

    /**
     * 用户参加活动赠送优惠券
     * @param userId 用户ID
     * @param activityId 活动ID
     */
    @RequestMapping("/giveActivityUserCode")
    public void giveActivityUserCode(@RequestParam("userId") BigDecimal userId,
                                     @RequestParam("activityId") BigDecimal activityId){
        opCouponCodeBiz.giveActivityUserCode(userId,activityId);
    }
}
